/**
 * Created by deng on 2016/4/27.
 */
var _Handlebar_ = {
    'group' : [
        '活动',
        '每天登录',
        '未启动(<7)',
        '未启动(>7)',
        '未登录'
    ],

    'face' : [
        '欢迎',
        '撒娇',
        '委屈'
    ],

    'action' : [
        '',
        '社区关注',
        '热门话题',
        '聊天室',
        '福利社',
        '精选回顾',
        '写日记',
        '我的记录',
        '每日一语',
        '天气',
        '手账',
        '登录注册',
        '同步',
        '主题馆',
        '信纸铺',
        '表情坊',
        '精选列表',
        '新鲜列表',
        '粉币乐园',
        '自定义跳转'
    ],
    'platform' : [
        '通用',
        'IOS',
        '安卓'
    ],
    'chatroomCategory' : [
        '',
        'K歌之王',
        '2333搞笑党',
        '一本正经聊感情',
        '不知道说什么',
        '星座游戏专区',
        '追星党的日常',
        '一起说方言',
        '二次元真好吃'
    ],
    'activityType' : {
        'launch':'开机页面',
        'banner':'社区Banner',
        'wisdom':'每日一语',
        'home_banner':'首页Banner',
        'recommend_banner':'推荐Banner',
        'homecat':'首页猫',
        'choicegroup':'精选圈子'
    },
    'roleType' : {
        '0':'未设置',
        '1':'学生',
        '2':'工作',
        '3':'自由'
    },
    'quantumType' : {
        '0':'未设置',
        '1':'午间',
        '2':'晚间'
    },
    'tipType' : {
        'morning':'粉粉早报',
        'ylmqq':'娱乐没圈圈',
        'jrbd':'今日必读',
        'msnbs':'美少女变身',
        'wafm':'晚安FM'
    },
    'userReportDealStatus':{
        '0' : '未处理',
        '1' : '已处理',
        '2' : '无效信息'
    },
    'shopActivityType' : {
        'planner':'手账推广',
        'dress':'个性装扮'
    },
    'clientRate':{
        '0':'0%',
        '20':'20%',
        '40':'40%',
        '60':'60%',
        '80':'80%',
        '100':'100%'
    },
    'vipType':{
        '0' : '购买',
        '1' : '添加',
        '2' : '试用'
    },
    'deviceStatus':{
        '0' : '使用中',
        '1' : '待审核'
    },
    'anonymousBgType':{
        'color' : '颜色',
        'image' : '图片'
    },
    'reviewRate':{
        '0' : '通过',
        '1' : '审核中',
        '2' : '未通过',
        '3' : '需人工处理'
    },
    'reviewOperate': {
        '0': '无',
        '1': '自动',
        '2': '人工'
    },
    'informType':{
        '1':'垃圾广告',
        '2':'虚假中奖',
        '3':'淫秽色情',
        '4':'敏感信息',
        '5':'泄露隐私',
        '6':'人身攻击',
        '7':'骚扰他人',
        '8':'冒充他人',
        '9':'不实信息',
        '10':'内容抄袭'
    },
    'codeStatus':{
        '0' : '未使用',
        '1' : '已使用',
        '2' : '已过期'
    },
    'payStatus':{
        '0' : '未付款',
        '1' : '已付款'
    },
    'accountsStatus':{
        '0' : '正常',
        '1' : '已封禁',
        '2' : '能收益不能支出',
        '3' : '能支出不能收益'
    },
    'orderStatus':{
        '0' : '未付款',
        '1' : '待发货',
        '2' : '待收货',
        '3' : '待评论',
        '4' : '已完成',
        '5' : '待退款'
    },
    'giftStatus':{
        '0' : '正常',
        '1' : '下线'
    },
    'giftType' : {
        '0':'通用',
        '1':'男生',
        '2':'女生',
        '3':'会员'
    },
    'accountsType' : {
        '0':'粉钻',
        '1':'打赏',
        '2':'礼物'
    },
    'orderChannel':{
        'alipay'            : '支付宝app',
        'alipay_wap'        : '支付宝手机网页',
        'alipay_pc_direct'  : '支付宝电脑网站',
        'bfb'               : '百度钱包',
        'bfb_wap'           : '百度钱包手机网页',
        'upacp'             : '银联支付',
        'upacp_wap'         : '银联手机网页',
        'wx'                : '微信app',
        'wx_pub'            : '微信公众号',
        'wx_pub_qr'         : '微信公众号扫码支付',
        'qpay'              : 'qq支付',
        'code'              : '兑换码'
    },
    'withdrawalStatus':{
        '0' : '未处理',
        '1' : '失败',
        '2' : '已完成'
    },
    'isTest':{
        '0' : '正式',
        '1' : '测试'
    },
    'isTestSelect':{
        '0' : '是',
        '1' : '否'
    }
}

var helperTimeConv = function(timestr){
    var times = Date.parse(timestr)/1000;
    var now = Date.parse(new Date())/1000;
    var time_inv = now - times;
    var ret = '';
    if(time_inv < 60){
        ret = time_inv + "秒前";
    }else if(time_inv<3600){
        time_inv = time_inv / 60;
        ret = parseInt(time_inv) + "分钟前";
    }else if(time_inv<3600*24){
        time_inv = time_inv/3600;
        ret = parseInt(time_inv) + "小时前";
    }else{
        ret = timestr.substring(5,16);
    }
    return ret;
}

var helperFormatDate = function(now)   {
    var now = new Date(now * 1000);
    var   year=now.getFullYear();
    var   month=now.getMonth()+1;
    month = month>9 ? month : '0' + month;
    var   date=now.getDate();
    date = date>9 ? date : '0' + date;
    var   hour=now.getHours();
    hour = hour>9 ? hour : '0' + hour;
    var   minute=now.getMinutes();
    minute = minute>9 ? minute : '0' + minute;
    var   second=now.getSeconds();
    second = second>9 ? second : '0' + second;
    return   year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second;
}

var helperNO2Text = function (group, v1, nulltext) {
    v1 = parseInt(v1);
    if (typeof nulltext == 'undefined') nulltext = '未知';
    if (typeof group[v1] == 'undefined')return nulltext;
    return group[v1];
}

var helperNO2StrText = function (group, v1, nulltext) {
    if (typeof nulltext == 'undefined') nulltext = '未知';
    if (typeof group[v1] == 'undefined')return nulltext;
    return group[v1];
}

var helperSelectGroup = function (group, v1) {
    var str = '';
    $.each(group, function (val, index) {
        if(v1 == val){
            str += '<option value="'+val+'" selected>'+index+'</option>';
        }else{
            str += '<option value="'+val+'">'+index+'</option>';
        }
    });
    return str;
}

Handlebars.registerHelper('robotGroupNO2Text', function(v1, options) {
    var group = _Handlebar_.group;
    return helperNO2Text(group, v1);
})

Handlebars.registerHelper('robotGroupSelect', function(v1, options) {
    var group = _Handlebar_.group;
    return helperSelectGroup(group, v1);
})

Handlebars.registerHelper('robotFaceNO2Text', function(v1, options) {
    var face = _Handlebar_.face;
    return helperNO2Text(face, v1);
})

Handlebars.registerHelper('robotFaceSelect', function(v1, options) {
    var face = _Handlebar_.face;
    return helperSelectGroup(face, v1);
})

Handlebars.registerHelper('robotActionNO2Text', function(v1, options) {
    var action = _Handlebar_.action;
    return helperNO2Text(action, v1);
})

Handlebars.registerHelper('robotActionSelect', function(v1, options) {
    var action = _Handlebar_.action;
    return helperSelectGroup(action, v1);
})

Handlebars.registerHelper('robotMsgStatusOpBtn', function(v1, v2,options) {
    if(v1 == 0){
        return '<button type="button" class="btn btn-danger myStatus" data-id="'+v2+'" data-status="'+v1+'">禁用</button>';
    }else{
        return '<button type="button" class="btn btn-default myStatus" data-id="'+v2+'" data-status="'+v1+'">使用</button>';
    }
})

Handlebars.registerHelper('robotMsgPlatformIcon', function(v1, options) {
    var icon = 'fa fa-soccer-ball-o';
    switch (parseInt(v1)){
        case 1:icon = 'fa fa-apple';break;
        case 2:icon = 'fa fa-android';break;
    }
    return '<i class="'+icon+'"></i>';
})

Handlebars.registerHelper('robotMsgPlatformSelect', function(v1, options) {
    var action = _Handlebar_.platform;
    return helperSelectGroup(action, v1);
})

Handlebars.registerHelper('dateConv', function(v1, options) {
    return helperFormatDate(parseInt(v1));
})

Handlebars.registerHelper('dateConvNew', function(v1, options) {
    if(v1 > 0){
        return helperFormatDate(parseInt(v1));
    }else{
        return '';
    }
})

Handlebars.registerHelper('dateConvExpire', function(v1, v2, options) {
    var time = Date.parse(new Date()); 
    time = time / 1000;
    if(v1 < time){
        if(v2 == 0){
            return '<label class="label label-danger">'+helperFormatDate(parseInt(v1))+'</label>';
        }
        return helperFormatDate(parseInt(v1));
    }else{
        return helperFormatDate(parseInt(v1));
    }
})

Handlebars.registerHelper('userReportinformTypeNO2Text', function(v1,v2, options) {
    var informType = _Handlebar_.informType;
    var str=helperNO2Text(informType, v2);
    var str1 = ''
    if(v1){
        str1 = '(说明:'+v1+')';
    }
    return str+str1;
})
Handlebars.registerHelper('timeConv', function(v1, options) {
    return new Date(parseInt(v1) * 1000).toLocaleString();
})

Handlebars.registerHelper('json2String', function(v1, options) {
    return JSON.stringify(v1);
})

Handlebars.registerHelper('chatroomCategorySelect', function(v1, options) {
    var face = _Handlebar_.chatroomCategory;
    return helperSelectGroup(face, v1);
})

Handlebars.registerHelper('chatroomCategoryNO2Text', function(v1, options) {
    var group = _Handlebar_.chatroomCategory;
    return helperNO2Text(group, v1);
})

Handlebars.registerHelper('activityTimeBeforeEnd', function(v1, options) {
    var now = Date.parse(new Date())/1000;
    var str = '';
    if (parseInt(v1)>now){
        str = '<i class="ion-checkmark-round" style="color:lightsalmon"><i/>';
    }else{
        str = '<i class="ion-close-round"><i/>';
    }
    return str;
})

Handlebars.registerHelper('activityTypeSelect', function(v1, options) {
    var group = _Handlebar_.activityType;
    return helperSelectGroup(group, v1);
})

Handlebars.registerHelper('roleTypeSelect', function(v1, options) {
    var group = _Handlebar_.roleType;
    return helperSelectGroup(group, v1);
})

Handlebars.registerHelper('quantumTypeSelect', function(v1, options) {
    var group = _Handlebar_.quantumType;
    return helperSelectGroup(group, v1);
})

Handlebars.registerHelper('showIsTestSelect', function(v1, options) {
    var group = _Handlebar_.isTestSelect;
    return helperSelectGroup(group, v1);
})

Handlebars.registerHelper('showIsTest', function(v1, options) {
    var face = _Handlebar_.isTest;
    return helperNO2Text(face, v1);
})

Handlebars.registerHelper('tipTypeSelect', function(v1, options) {
    var group = _Handlebar_.tipType;
    return helperSelectGroup(group, v1);
})

Handlebars.registerHelper('shopActivityTypeSelect', function(v1, options) {
    var group = _Handlebar_.shopActivityType;
    return helperSelectGroup(group, v1);
})

Handlebars.registerHelper('activityTypeNO2Text', function(v1, options) {
    var group = _Handlebar_.activityType;
    v1 = v1.toLocaleLowerCase();
    return group[v1];
})

Handlebars.registerHelper('roleTypeNO2Text', function(v1, options) {
    var group = _Handlebar_.roleType;
    //console.log(v1);
    v1 = v1.toLocaleLowerCase();
    return group[v1];
})

Handlebars.registerHelper('quantumTypeNO2Text', function(v1, options) {
    var group = _Handlebar_.quantumType;
    v1 = v1.toLocaleLowerCase();
    return group[v1];
})

Handlebars.registerHelper('shopActivityTypeNO2Text', function(v1, options) {
    var group = _Handlebar_.shopActivityType;
    v1 = v1.toLocaleLowerCase();
    return group[v1];
})

Handlebars.registerHelper('isWisdom', function(v1, options) {
    if (v1=='wisdom'){
        return 'display: inline-block';
    }
    return 'display:none';
})

Handlebars.registerHelper('userReportDealstatusNO2Text', function(v1, options) {
    var group = _Handlebar_.userReportDealStatus;
    return helperNO2Text(group, v1);
})

Handlebars.registerHelper('userReportDealstatusNO2Style', function(v1, options) {
    if (parseInt(v1)==0){
        return 'info';
    }
    return 'default';
})

Handlebars.registerHelper('topicsCategoryGroupSelect', function(group, v1, options) {
    return helperSelectGroup(group, v1);
})

Handlebars.registerHelper('topicsCategorySort', function(v1, options) {
    return parseInt(v1)==0 ? ' (默认话题)' : '';
})

Handlebars.registerHelper('clientRateSelect', function(v1, options) {
    var group = _Handlebar_.clientRate;
    return helperSelectGroup(group, v1);
})

Handlebars.registerHelper('vipTypeNO2Text', function(v1, options) {
    var face = _Handlebar_.vipType;
    return helperNO2Text(face, v1);
})

Handlebars.registerHelper('codeStatusText', function(v1, v2, options) {
    var face = _Handlebar_.codeStatus;
    var time = Date.parse(new Date()); 
    time = time / 1000;
    if(v2 < time){
        if(v1 == 0){
            return '<label class="label label-danger">'+helperNO2Text(face, 2)+'</label>';
        }
    }
    if(v1 == 0){
        return helperNO2Text(face, v1);
    }else{
        return '<label class="label label-info">'+helperNO2Text(face, v1)+'</label>';
    }
})

Handlebars.registerHelper('useCodeUid', function(v1, options) {
    if(v1 == 0){
        return v1;
    }else{
        return '<label class="label label-success">'+v1+'</label>';
    }
})

Handlebars.registerHelper('payStatusText', function(v1, options) {
    var face = _Handlebar_.payStatus;
    return helperNO2Text(face, v1);
})

//账户状态
Handlebars.registerHelper('accountsStatusText', function(v1, options) {
    var face = _Handlebar_.accountsStatus;
    return helperNO2Text(face, v1);
})
//账户类型
Handlebars.registerHelper('accountsTypeNO2Text', function(v1, options) {
    var face = _Handlebar_.accountsType;
    return helperNO2Text(face, v1);
})

Handlebars.registerHelper('orderStatusText', function(v1, options) {
    var face = _Handlebar_.orderStatus;
    return helperNO2Text(face, v1);
})

//礼物状态
Handlebars.registerHelper('giftStatusText', function(v1, options) {
    var face = _Handlebar_.giftStatus;
    return helperNO2Text(face, v1);
})

//礼物类型
Handlebars.registerHelper('giftTypeNO2Text', function(v1, options) {
    var group = _Handlebar_.giftType;
    v1 = v1.toLocaleLowerCase();
    return group[v1];
})

//礼物类型下拉菜单
Handlebars.registerHelper('giftTypeSelect', function(v1, options) {
    var group = _Handlebar_.giftType;
    return helperSelectGroup(group, v1);
})

//礼物类型下拉菜单
Handlebars.registerHelper('giftStatusSelect', function(v1, options) {
    var group = _Handlebar_.giftStatus;
    return helperSelectGroup(group, v1);
})
Handlebars.registerHelper('orderChannelText', function(v1, options) {
    var face = _Handlebar_.orderChannel;
    return helperNO2StrText(face, v1);
})

Handlebars.registerHelper('withdrawalStatusText', function(v1, options) {
    var face = _Handlebar_.withdrawalStatus;
    var text = helperNO2Text(face, v1);
    if(v1 == 0){
        return '<label class="label label-info">'+text+'</label>';
    }else if(v1 == 1){
        return '<label class="label label-danger">'+text+'</label>';
    }else if(v1 == 2){
        return '<label class="label label-success">'+text+'</label>';
    }else{
        return text;
    }
})

Handlebars.registerHelper('withdrawalAction', function(v1, v2, v3, options) {
    if(v1 == 0){
        return '<button type="button" class="btn btn-danger reject" data-id="'+v2+'">驳回申请</button>'+
                '<button type="button" class="btn btn-success myUpdate" data-id="'+v2+'">确认打款</button>';
    }else{
        return '';
    }
})
//pay_status=>v1 business=>v2 uid=>v3 order_id=>v4
Handlebars.registerHelper('businessAction', function(v1, v2, v3, v4 ) {
    if(v1 == 0 ){
        if(v2 == 1 || v2 ==2 || v2 == 4 || v2 == 6)
        {
            return'<button type="button" class="btn btn-info update" data-uid="'+v3+'" data-order="'+v4+'">补单</button>';
        }
    }else{
        return '';
    }
})

Handlebars.registerHelper('deviceStatusNO2Text', function(v1, options) {
    var face = _Handlebar_.deviceStatus;
    return helperNO2Text(face, v1);
})

Handlebars.registerHelper('deviceStatusOpBtn', function(v1, v2,options) {
    if(v1 == 0){
        return '';
    }else{
        return '<button type="button" class="btn btn-info myEdit" data-id="'+v2+'">审核通过</button>';
    }
})
Handlebars.registerHelper('anonymousBgTypeSelect', function(v1, options) {
    var group = _Handlebar_.anonymousBgType;
    return helperSelectGroup(group, v1);
})

Handlebars.registerHelper('diaryReviewRateNO2Text', function(v1, options) {
    var v = _Handlebar_.reviewRate;
    return helperNO2Text(v, v1);
})

Handlebars.registerHelper('diaryReviewOperateNO2Text', function(v1, options) {
    var v = _Handlebar_.reviewOperate;
    return helperNO2Text(v, v1);
})

Handlebars.registerHelper('diaryReviewVideoUrl', function(videoList, options) {
    if (videoList && videoList[0] && videoList[0]['attachmentPath']){
        return videoList[0]['attachmentPath'];
    }
    return '';
})

Handlebars.registerHelper('isYearVip', function(v1, options) {
    var now = Date.parse(new Date())/1000;
    if (now<v1){
        return '<span style="font-size: 14px;color: red">年</span>';
    }
    return '';
})